package com.sky.controller.admin;


import com.sky.annotation.ActionLog;
import com.sky.dto.BookDTO;
import com.sky.dto.PageQuery;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.BookServiceImpl;
import com.sky.vo.BookVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController("adminBookController")
@Api(tags = "管理端端-图书的相关接口")
@Slf4j
@RequestMapping("/admin/book")
public class BookController {
    @Autowired
    private BookServiceImpl bookService;

    /**
     * 根据查询关键词获取图书列表
     *
     * @param pageQuery
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("根据关键词获取图书信息")
    public Result<PageResult> pageQuery(PageQuery pageQuery) {
        log.info("搜索关键词:{}", pageQuery);
        PageResult result = bookService.pageQuery(pageQuery);
        return Result.success(result);
    }

    /**
     * 添加图书
     *
     * @param bookDTO
     * @return
     */
    @PostMapping
    @ApiOperation("添加图书")
    @ActionLog(value = "添加了图书",module = "图书管理模块")
    public Result add(@RequestBody BookDTO bookDTO) {
        log.info("bookFormDTO:{}", bookDTO);
        return Result.success();
    }

    /**
     * 根据图书id获取详情
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("根据图书id获取图书详情")
    public Result<BookVO> detailById(@PathVariable String id) {
        BookVO bookVO = bookService.detailById(id);
        log.info("bookTableVO:{}", bookVO);
        return Result.success(bookVO);
    }

    /**
     * 修改图书
     *
     * @param bookDTO
     * @return
     */
    @PutMapping
    @ApiOperation("修改图书")
    @ActionLog(value = "修改了图书",module = "图书管理模块")
    public Result update(@RequestBody BookDTO bookDTO) {
        return Result.success();
    }

    /**
     * 根据id删除图书
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除图书")
    @ActionLog(value = "删除了图书",module = "图书管理模块")
    public Result delete(@PathVariable String id) {
        return Result.success();
    }


}
